$(function(){
	question_import.initial();
});
var opts = {
    lines: 10, // The number of lines to draw
    length: 18, // The length of each line
    width: 10, // The line thickness
    radius: 15, // The radius of the inner circle
    scale: 1, // Scales overall size of the spinner
    corners: 1, // Corner roundness (0..1)
    color: '#000', // CSS color or array of colors
    fadeColor: 'transparent', // CSS color or array of colors
    speed: 1, // Rounds per second
    rotate: 0, // The rotation offset
    animation: 'spinner-line-fade-quick', // The CSS animation name for the lines
    direction: 1, // 1: clockwise, -1: counterclockwise
    zIndex: 2e9, // The z-index (defaults to 2000000000)
    className: 'spinner', // The CSS class to assign to the spinner
    top: '50%', // Top position relative to parent
    left: '50%', // Left position relative to parent
    shadow: '0 0 1px transparent', // Box-shadow for the lines
    position: 'absolute' // Element positioning
};

var spinner = new Spinner(opts);
var target = document.getElementById('img_wait');
var upload = layui.upload;
var question_import={
		initial : function initial() {
			this.prepareUploadify();
			this.questionDataProcess();
		},
		prepareUploadify : function prepareUploadify(){
            layui.use('upload', function () {
                var upload = layui.upload;
                //执行实例
                var uploadInst = upload.render({
                    elem: '#test1', //绑定元素
                    url: '/admin/upload-uploadify', //上传接口
                    size: 1000,
                    accept: 'file',
                    done: function (data) {
                      $('#div-file-list').html('<a class=\'file-name\'>'
                        					+ data.file
                        					+ '</a><input type=\'hidden\' value=\''
                        					+ data.file + '\' />');
                    },
                    error: function (r) {
                        layer.msg(r.msg);
                    }
                });
            });
		},
		questionDataProcess : function questionDataProcess(){
			$("#from-question-import").submit(function(){
                spinner.spin(target);
                $(document).mask();
				var filePath = $("#div-file-list").find("input").val();
				$.ajax({
					headers : {
						'Accept' : 'application/json',
						'Content-Type' : 'application/json'
					},
					type : "POST",
					url : $("#from-question-import").attr("action") + "/" + $(".upload-question-group select").val(),
					data : filePath,
					success : function(message, tst, jqXHR) {
						if (!util.checkSessionOut(jqXHR))
							return false;
						if (message.result == "success") {
                            $(document).unmask();
                            spinner.spin();
							util.success("导入成功", function() {
								$("#submit-div .form-message").text(message.messageInfo);
								//document.location.href = document.getElementsByTagName('base')[0].href + 'admin/course-list';
							});
						} else {
                            $(document).unmask();
                            spinner.spin();
							util.error(message.messageInfo);
							$("#btn-add-submit").removeAttr("disabled");
						}
					},
					error : function(jqXHR, textStatus) {
                        spinner.spin();
                        $(document).unmask();
						util.error("操作失败请稍后尝试");
						$("#btn-add-submit").removeAttr("disabled");
					}
				});
				return false;
			});
		}
};
